package com.freewater.cargotracker.domain.shared;

import org.apache.commons.lang3.Validate;

public class AndSpecification<T> extends AbstractSpecification<T> {

    private Specification<T> one;
    private Specification<T> other;

    public AndSpecification(Specification<T> one, Specification<T> other) {
        Validate.notNull(one, "Specification is required");
        Validate.notNull(other, "Specification is required");

        this.one = one;
        this.other = other;
    }

    @Override
    public boolean isSatisfiedBy(T t) {
        return one.isSatisfiedBy(t) && other.isSatisfiedBy(t);
    }
}
